package rwt.server.handlers;

import org.slf4j.*;

import rwt.server.RailServer;
import rwt.server.RailroadMessages.SwRepMsg;
import rwt.server.WebMessages.PutSwitchState;
import rwt.server.core.*;
import rwt.server.railroad.Switches;

public class SwRepHandler extends MessageHandler<SwRepMsg>
{
	private static final Logger logger = LoggerFactory.getLogger(SwRepHandler.class);
	
	@Override
	public void handle(SwRepMsg message, IConnection source) throws Exception
	{
		RailServer.getSwitchManager().SetSwitch(message.switchId, message.state);
		PutSwitchState webMsg = new PutSwitchState(message.switchId, message.state);
		logger.info("SwRepmsg " + message.switchId + " " + message.state);
		Switches.getInstance().sendToAll(webMsg);
	}
}
